<?php
/**
 *
 *
 * @author: mgli<mgli@kaikeba.com>
 * @date: 2021/3/1
 * @version: 1.0
 * @copyright: mgli@kaikeba.com @ 2021
 * @filename: TeamTable.php
 */

namespace App\Admin\RenderAble;

use App\Admin\Repositories\OrgTeam;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class TeamTable extends LazyRenderable
{


    /**
     * 创建表格.
     *
     * @return Grid
     */
    public function grid(): Grid
    {
        return Grid::make(new OrgTeam(['owners.username']), function(Grid $grid){
            $grid->model()->where('department_id', request('key'))->orderBy('team_id', 'desc');
            $grid->column('team_id', '小组ID');
            $grid->column('name', '小组名称');
            $grid->owners('负责人')->display(function($users){
                $user_str = [];
                foreach ($users as $user){
                    $user_str[] = '<span class="badge" style="background:#5c6bc6">'.$user['username']['name'].'</span>';
                }
                return implode(' ', $user_str);
            });
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableFilter();
            $grid->disableFilterButton();
        });
    }
}